
window.com = {};
import config from './config'

(function(){

    this.getEnv = function(){
        return this.getCookie('env') ? this.getCookie('env') : 'dev'
    };
    this.textFormat = function(content){
        var code = encodeURIComponent(content);
        return decodeURIComponent(code.replace(/%0/g,'<br/>'));
    };
    this.setData = function(type,sign,hours){
        localStorage.removeItem(type);
        var signObj = sign;
        //设置过期时间
        var time = new Date().getTime() + hours*60*60*1000;
        signObj.expire = time;
        localStorage.setItem(type,JSON.stringify(signObj));
    };
    this.getData = function(type,key){
        var data = JSON.parse(localStorage.getItem(type)||localStorage.getItem(type));
        if(data){
            var d = new Date().getTime();
            if(d>data['expire']){
                return false;
            }else{
                return data[key];
            }
        }
    };
    this.setCookie = function(name,value,hours){
        var expdate = new Date();
        expdate.setTime(expdate.getTime()+hours*360*1000);
        document.cookie = name+'='+encodeURIComponent(value)+';expires='+expdate.toUTCString()+";path=/";
    };
    this.getCookie = function(c_name){
        if(document.cookie.length>0){
            var arrstr = document.cookie.split("; ");
            for(var i = 0;i<arrstr.length;i++){
                var temp = arrstr[i].split("=");
                if(temp[0] == c_name) {return decodeURIComponent(temp[1]); }
            }
        }
    };
    this.config = config;

}).apply(com);